package net.kucoe.grin;

import net.kucoe.grin.server.EmptyServer;
import net.kucoe.grin.server.GrinServer;

/**
 * Services utility class.
 * 
 * @author Vitaliy Basyuk
 */
public class Services {
    
    private static GrinServer server;
    
    /**
     * Returns the server GrinServer.
     * 
     * @return the server GrinServer.
     */
    public static GrinServer getServer() {
        if (server == null) {
            try {
                Class<?> clazz = Class.forName("net.kucoe.grin.server.GrinServerImpl");
                server = (GrinServer) clazz.newInstance();
            } catch (ClassNotFoundException e) {
                server = new EmptyServer();
            } catch (InstantiationException e) {
                server = new EmptyServer();
            } catch (IllegalAccessException e) {
                server = new EmptyServer();
            }
        }
        return server;
    }
}
